<div class="layuimini-container layuimini-page-anim">
    <div class="layuimini-main">
        <form class="layui-form" action="" style="padding:20px;">
            <div class="layui-form-item">
                <label class="layui-form-label">负责人</label>
                <div class="layui-input-inline">
                    <input type="text" name="users" placeholder="用户名" readonly="readonly" autocomplete="off"
                        class="layui-input" id="users" value="" ts-selected="">
                </div>
            </div>

            <div class="layui-form-item">
                <div class="layui-input-block">
                    <button class="layui-btn" lay-submit lay-filter="saveBtn">确认保存</button>
                </div>
            </div>
        </form>
    </div>
</div>


<script>
    var data = parent.editData;
    idList = []
    nameList = []
    departmentCode = data.departmentCode
    // for (let index = 0; index < data.leaderIDs.split(';').length; index++) {
    //     idList.push(data.leaderIDs.split(';')[index])
    // }
    // for (let index = 0; index < data.leaderNames.split(';').length; index++) {
    //     nameList.push(data.leaderNames.split(';')[index])
    // }

    document.getElementById('users').value = data.leaderNames;
    document.getElementById('users').setAttribute('ts-selected', data.leaderIDs.replace(new RegExp(";", "gm"), ","));

    layui.use(['table', 'form', 'tableSelect'], function () {
        var $ = layui.jquery,
            table = layui.table,
            form = layui.form,
            tableSelect = layui.tableSelect;

        tableSelect.render({
            elem: '#users',
            searchKey: 'user', //表格的唯一建值，非常重要，影响到选中状态 必填
            checkedKey: 'id',//搜索输入框的name值 默认keyword
            searchPlaceholder: '输入用户名或ID',
            table: {
                url: config.server + "/adminPermission/getuser",
                cols: [[
                    { type: 'checkbox' },
                    { align: 'center', title: '序号', type: 'numbers', width: 50 },
                    { field: 'id', title: 'ID', width: 140 },
                    { field: 'name', title: '姓名', width: 140 },
                    { field: 'showDepartment', title: '部门', width: 140 }
                ]],
                headers: {
                    token: shared.getCookie('token'),
                },
                limit: 6
            },
            done: function (elem, data) {
                for (let index = 0; index < data.data.length; index++) {
                    const element = data.data[index];
                    idList.push(element.id)
                    nameList.push(element.name)
                }
                elem.val(nameList.join(";"))
            }
        })


    });


</script>